package com.mytijian.openapi.adapter.alihalt.job;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.mytijian.openapi.core.model.AppConfig;
import com.mytijian.openapi.core.service.OpenApiAppConfigService;

@Component
public class AlihaltOpenAPIAccessTokenUpdateJob implements SimpleJob {

	private Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private OpenApiAppConfigService openAPIService;

	@Override
	public void execute(ShardingContext arg0) {
		log.info("[开放平台适配层] 更新open-api accessToken任务开始执行");
		
		List<AppConfig> configs = openAPIService.listConfigs();
		for (AppConfig config : configs) {
			try {
				openAPIService.updateAccessToken(config);
			} catch (Exception e) {
				log.error("!!! [开放平台适配层] 更新open-api accessToken任务失败 {}", e);
			}
		}
	}

}
